package ch.ethz.fcl.metrobuzz.controller.timer;

import ch.ethz.fcl.metrobuzz.MBContainer;
import ch.ethz.fcl.metrobuzz.MBProperty;

/**
 * Timer controller to animate the interactions
 * 
 * @author Zeng Wei
 * @email zeng@arch.ethz.ch
 * 
 */
public class Timer implements Runnable {
	private MBContainer container = null;

	public Timer(MBContainer container) {
		this.container = container;
	}

	@Override
	public void run() {
		while (MBProperty.REGIONS) {
			try {
				Thread.sleep(50);
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (container.getViewer().getCamera().getDistance() >= 0.5f)
				container.getViewer().getCamera().addDistance(-0.015f);
			else
				container.getViewer().getCamera().addDistance(-0.01f);

			if (container.getViewer().getCamera().getDistance() <= 0.2f) {
				try {
					Thread.sleep(3000);
				} catch (Exception e) {
					e.printStackTrace();
				}
				container.getViewer().getCamera().setDistance(1.2f);
				try {
					Thread.sleep(2000);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
